/**
 * @Description: 全自动化指令
 * @author Beon
 * @date 2021/1/4
 */
import {OraLoading} from '../decorators/oraLoading';
import {Command} from '../types/command';
import {ClassTool} from '../decorators/classTool';
import {LzCommit} from './lzCommit';
import {LzPush} from './lzPush';
import {LzMr} from './lzMr';
import {OtherInquirer} from '../inquirer/otherInquirer';

export class Lz implements Command{

    @OraLoading.beProxy
    status: OraLoading // 执行状态
    static baseConfirm = {
        type: 'confirm',
        name: 'checkNext',
        message: ''
    }

    constructor() {
        this.status.value = '自动化执行';
    }

    /**
     * 指令运行函数
     * @param {[String]} arg 参数
     * @returns {Promise<void>}
     */
    @ClassTool.saveThis
    async done(arg?: [string]): Promise<void> {
        await new LzCommit().done(arg);

        await Lz.checkNextStep('是否自动push') && await new LzPush().done(arg);

        await Lz.checkNextStep('是否提交mr请求') && await new LzMr().done(arg);
    }

    /**
     * 检验下一步操作
     * @param message
     * @returns {Promise<boolean>}
     */
    static async checkNextStep(message: string): Promise<boolean> {
        this.baseConfirm.message = message;

        return (await OtherInquirer.baseInquirer([this.baseConfirm])).checkNext as boolean;
    }
}
